
using System;
using QdbUnit;
using QdbUnit.Extensions;
using Qdb;
using Qdb.Config;
using Qdb.Internal;
using Qdb.Tests.Common.Exceptions;

namespace Qdb.Tests.Common.Exceptions
{
	public class StoreExceptionBubblesUpTestCase : AbstractQdbTestCase
	{
		public static void Main(string[] args)
		{
			new StoreExceptionBubblesUpTestCase().RunNetworking();
		}

		public sealed class ItemTranslator : IObjectTranslator
		{
			public void OnActivate(IObjectContainer container, object applicationObject, object
				 storedObject)
			{
			}

			public object OnStore(IObjectContainer container, object applicationObject)
			{
				throw new ItemException();
			}

			public Type StoredClass()
			{
				return typeof(Item);
			}
		}

		protected override void Configure(IConfiguration config)
		{
			config.ObjectClass(typeof(Item)).Translate(new StoreExceptionBubblesUpTestCase.ItemTranslator
				());
		}

		public virtual void Test()
		{
			ICodeBlock exception = new _ICodeBlock_41(this);
			Assert.Expect(typeof(ReflectException), exception);
		}

		private sealed class _ICodeBlock_41 : ICodeBlock
		{
			public _ICodeBlock_41(StoreExceptionBubblesUpTestCase _enclosing)
			{
				this._enclosing = _enclosing;
			}

			/// <exception cref="System.Exception"></exception>
			public void Run()
			{
				this._enclosing.Store(new Item());
			}

			private readonly StoreExceptionBubblesUpTestCase _enclosing;
		}
	}
}
